package rd.hardcore.ui 
{
	import aze.motion.eaze;
	import caurina.transitions.Tweener;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	import rd.hardcore.events.SoundSystemEvent;
	import rd.hardcore.params.GlobalParams;
	
	/**
	 * ...
	 * @author Romain Prache
	 */
	public class StopButton extends StopButton_FC
	{
		private var shadow 		: DropShadowFilter;
		private var actived		: Boolean;
		
		public function StopButton() 
		{
			y = 288;
			x = GlobalParams.WIDTH - width - 30;
			mouseChildren = false;
			alpha = 0;
			
			shadow = new DropShadowFilter(1, 90, 0, .35, 5, 5, 1, 2);
			body.filters = [shadow];
			
		}
		
		public function active( evt : Event = null ) : void
		{
			if (actived) return;
			actived = true;
			
			eaze(this).to(.3, { alpha:1 } ).onComplete(addEvent);
			
			buttonMode = true;
			addEventListener(MouseEvent.CLICK, 		handleClick);
		}
		
		private function addEvent():void
		{
			if(actived){
				addEventListener(MouseEvent.ROLL_OVER, 	handleOver);
				addEventListener(MouseEvent.ROLL_OUT, 	handleOut);
			}
		}
	
		
		public function unactive( evt : Event = null ) : void
		{
			if (!actived) return;
			actived = false;
			
			buttonMode = false;
			removeEventListener(MouseEvent.CLICK, 		handleClick);
			removeEventListener(MouseEvent.ROLL_OVER, 	handleOver);
			removeEventListener(MouseEvent.ROLL_OUT, 	handleOut);

			eaze(this).to(.3, {alpha:0}).colorMatrix(0);
		}
		
		private function handleClick(e:MouseEvent):void 
		{
			unactive();
			
			dispatchEvent(new SoundSystemEvent(SoundSystemEvent.KILL_SOUND, null, true) );
		}
		
		private function handleOver(e:MouseEvent):void 
		{
			eaze(this).to(.4).colorMatrix( -.15);
		}
		
		private function handleOut(e:MouseEvent):void 
		{
			eaze(this).to(.3).colorMatrix(0);
		}
		
	}

}